﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MES.Desktop.Utils
{
    public class FunctionUtil
    {
        public static string GetRole(DependencyObject obj)
        {
            return (string)obj.GetValue(RoleProperty);
        }

        public static void SetRole(DependencyObject obj, string value)
        {
            obj.SetValue(RoleProperty, value);
        }
        public static readonly DependencyProperty RoleProperty =
            DependencyProperty.RegisterAttached("Role",
                typeof(string),
                typeof(FunctionUtil),
                new PropertyMetadata("0", new PropertyChangedCallback(OnRoleChanged)));

        public static void OnRoleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            string[] ids = e.NewValue.ToString().Split(',');

            var fe = (d as FrameworkElement);

            if (!ids.Contains(fe.Tag.ToString()))
                fe.Visibility = Visibility.Collapsed;

        }
    }
}
